package com.wkedu.repair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wkedu.repair.dao.RepairStudentMapper;
import com.wkedu.repair.dto.RepairStudentDto;
import com.wkedu.repair.entity.RepairStudent;
import com.wkedu.repair.service.RepairStudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 港港
 * @version 1.0
 * @date 2021/9/6 3:32 下午
 */
@Service
@Transactional
public class RepairStudentServiceImpl implements RepairStudentService {

    @Resource
    private RepairStudentMapper repairStudentMapper;

    @Override
    public void add(RepairStudentDto repairStudentDto) {
        RepairStudent repairStudent = new RepairStudent();
        repairStudent.setRepairType(repairStudentDto.getRepairType());
        repairStudent.setRepairPath(repairStudentDto.getRepairPath());
        repairStudent.setStudentId(repairStudentDto.getStudentId());
        repairStudent.setRepairInfo(repairStudentDto.getRepairInfo());
        repairStudentMapper.insert(repairStudent);
    }

    @Override
    public List<RepairStudentDto> listForStudentId(String studentId) {
        QueryWrapper<RepairStudent> wrapper = new QueryWrapper<>();
        wrapper.eq("student_id",studentId);
        List<RepairStudent> repairStudents = repairStudentMapper.selectList(wrapper);
        if (repairStudents != null){
            List<RepairStudentDto> collect = repairStudents.stream().map(i -> new RepairStudentDto(
                    i.getRepairInfo(), i.getRepairPath(), i.getRepairType(), i.getStudentId()
            )).collect(Collectors.toList());
            return collect;
        }else {
            return null;
        }
    }

    @Override
    public RepairStudentDto getForInfo(String info) {

        return null;
    }
}
